package com.wss.day10;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/5/7
 */
public class PredicateExample {
    public static void main(String[] args) {
        String[] array = {"张三,男", "李四,女", "王二麻子,女"};

        Predicate<String> isFemale = s -> s.endsWith(",女");

        Predicate<String> hasFourCharacterName = s -> {
            String name = s.split(",")[0];
            return name.length() == 4;
        };

        // 组合两个条件
        Predicate<String> combinedPredicate = isFemale.and(hasFourCharacterName);

        // 筛选符合条件的字符串
        List<String> filteredList = new ArrayList<>();
        for (String str : array) {
            if (combinedPredicate.test(str)) {
                filteredList.add(str);
            }
        }
        System.out.println(filteredList);

    }
}